package com.adong.service;

import com.adong.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.inject.Inject;
import javax.naming.Name;

/**
 * @author adong
 */
@Service
public class UserService {

    //@Qualifier("userDao2") //当容器中有多个这个类型的bean时可以使用Qualifier去规定选择装配那个bean
    @Autowired
    //@Autowired(required = false) 自动装配一定要bean在容器中,设置为true的话,容器中没有这个bean也会注入一个null 输出UserService的bean:UserService{userDao=null}
    //@Resource(name = "userDao2")
    private UserDao userDao; //没有@Qualifier() 注解会会根据你定义的属性名来去寻找容器中bean的名称,例如:private UserDao userDao2 ,他就回去容器中需按照优先userDao2的bean;

    public void print() {
        System.out.println(userDao);
    }

    @Override
    public String toString() {
        return "UserService{" +
                "userDao=" + userDao +
                '}';
    }
}
